# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file '在状态栏中实时显示当前时间.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2 import QtWidgets, QtGui, QtCore
import sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)

        # 添加一个状态栏
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)
        timer = QtCore.QTimer(MainWindow)      # 创建一个QTimer计时器对象
        timer.timeout.connect(self.showtime)      # 发射timeoout信号，与自定义槽函数关联
        timer.start()

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u5728\u72b6\u6001\u680f\u4e2d\u5b9e\u65f6\u663e\u793a\u5f53\u524d\u65f6\u95f4", None))
    # retranslateUi

    # 自定义槽函数，用来在状态栏中显示当前日期时间
    def showtime(self):
        datetime = QtCore.QDateTime.currentDateTime()
        text = datetime.toString("yyyy-MM-dd HH:mm:ss")     # 对获取的时间格式化
        self.statusbar.showMessage('当前日期时间为：' + text, 0)
        # self.retranslateUi(MainWindow)
        # QtCore.QMetaObject.connectSlotsByName(MainWindow)


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

